<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="年级：" ref="nianji">
        <el-select v-model="formInline.region" placeholder="年级">
          <el-option label="1年级" value="yinianji"></el-option>
          <el-option label="2年级" value="ernianji"></el-option>
          <el-option label="3年级" value="sannianji"></el-option>
          <el-option label="4年级" value="sinianji"></el-option>
          <el-option label="5年级" value="wunianji"></el-option>
          <el-option label="6年级" value="liunianji"></el-option>
          <el-option label="初一" value="chuyi"></el-option>
          <el-option label="初二" value="chuer"></el-option>
          <el-option label="初三" value="chusan"></el-option>
          <el-option label="高一" value="gaoyi"></el-option>
          <el-option label="高二" value="gaoer"></el-option>
          <el-option label="高三" value="gaosan"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="subjectId" label="id" width="310">
      </el-table-column>
      <el-table-column prop="subjectName" label="学科" width="310">
      </el-table-column>
      <el-table-column prop="subjectClass" label="年级" width="310">
      </el-table-column>
      <el-table-column prop="caozuo" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="del(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { xklb, dellist } from "@/apis/lihan/Index.js";
export default {
  data() {
    return {
      formInline: {
        user: "",
        region: "",
      },
      tableData: [],
      page: 1,
      limit: 10,
      total: 10,
    };
  },
  mounted() {
    this.link();
  },
  methods: {
    // 数据展示
    link() {
      xklb().then((ok) => {
        this.tableData = ok.data.data;
      });
    },

    // 查询
    onSubmit() {
      if (this.formInline.value != "") {
        xklb(this.formInline.user).then((ok) => {
          console.log(ok);
          this.tableData = ok.data.data;
        });
      }
    },

    getData() {
      xklb(this.page, this.limit).then((ok) => {
        this.tableData = ok.data.data;
        this.total = ok.data.data.length;
      });
    },

    // 分页
    // 每页显示的条数
    handleSizeChange(val) {
      // 改变每页显示的条数
      (this.limit = val), this.link();
    },
    // 显示第几页
    handleCurrentChange(val) {
      // 改变默认的页数
      (this.page = val), this.link();
    },

    del(index, row) {
      console.log(index, row.subjectId);
      dellist(row.subjectId).then((ok) => {
        console.log(ok);
        this.link();
        this.$message({
          message: "删除成功！",
          type: "success",
        });
      });
    },
    handleEdit(index, row) {
      this.$router.push("/xkcb");
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
  },
};
</script>

<style scoped>
</style>